/**
 * Created by Administrator on 2017/3/22 0022.
 */
var Page1={
    create:function()
    {
        var page={};
        var bool_down;
        var startY;
        var downY;
        var speed=0;
        var subIdx=0;
        page.ui=new PIXI.DisplayObjectContainer();

        var bg=new PIXI.Graphics();
        bg.beginFill(0xffffff,1);
        bg.drawRect(0,0,pixiStageW,pixiStageH);
        bg.endFill();
        page.ui.addChild(bg);

        var con_clock=new PIXI.DisplayObjectContainer();
        //con_clock.anchor.set(0.5);
        //con_clock.pivot.x=pixiStageW/2;
        //con_clock.pivot.y=pixiStageH/2;
        con_clock.x=pixiStageW/2;
        con_clock.y=pixiStageH/2;
        page.ui.addChild(con_clock);

        var sp_frame=new PIXI.Sprite(resource['assets/images/p1_frame.png'].texture);
        sp_frame.anchor.set(243/538,270/500);
        //sp_frame.pivot.x=pixiStageW/2;
        //sp_frame.pivot.y=pixiStageH/2;
        sp_frame.x=-2;
        sp_frame.y=-3;
        con_clock.addChild(sp_frame);
        //TweenMax.to(sp_frame,4,{rotation:2*Math.PI,repeat:-1});

        var sp_clock=new PIXI.Sprite(resource['assets/images/p1_clock.png'].texture);
        sp_clock.anchor.set(0.5);
        sp_clock.width=490;
        sp_clock.height=477;
        // sp_clock.scale.x=sp_clock.scale.y=0.35;
        sp_clock.x=-1;
        sp_clock.y=-1;
        con_clock.addChild(sp_clock);

        var sp_m=new PIXI.Sprite(resource['assets/images/p1_m.png'].texture);
        sp_m.anchor.set(7/12,1-90/82.5);
        sp_m.x=-37;
        sp_m.y=-57;
        con_clock.addChild(sp_m);
        TweenMax.to(sp_m,8,{rotation:Math.PI*2,ease:Linear.easeNone,repeat:-1});


        var sp_h=new PIXI.Sprite(resource['assets/images/p1_h.png'].texture);
        sp_h.anchor.set(1-166/143,17/35);
        sp_h.x=-37;
        sp_h.y=-57;
        con_clock.addChild(sp_h);
        TweenMax.to(sp_h,8*12,{rotation:Math.PI*2,ease:Linear.easeNone,repeat:-1});

        var sp_center=new PIXI.Sprite(resource['assets/images/p1_center.png'].texture);
        sp_center.anchor.set(0.5);
        sp_center.x=-36.5;
        sp_center.y=-56;
        sp_center.scale.x=sp_center.scale.y=1.2;
        con_clock.addChild(sp_center);



        var tip=new PIXI.Sprite(resource['assets/images/p1_tip.png'].texture);
        tip.anchor.set(0.5);
        tip.x=191;
        tip.y=327;
        page.ui.addChild(tip);
        TweenMax.to(tip,1,{y:327+30,yoyo:true,repeat:-1,ease:Cubic.easeInOut});

        var hand=new PIXI.Sprite(resource['assets/images/p1_hand.png'].texture);
        hand.anchor.set(0.5);
        hand.x=0;
        hand.y=0;
        page.ui.addChild(hand);
        hand.on('pointerdown',downHandler);
        hand.on('pointermove',moveHandler);
        hand.on('pointerup',upHandler);

        var int;
        page.In=function(_subIdx)
        {
            hand.interactive=false;
            bool_down=false;
            speed=0;

            subIdx=_subIdx;
            con_clock.scale.x=con_clock.scale.y=3;
            TweenMax.to(sp_frame,2,{delay:1,rotation:4*Math.PI});
            TweenMax.to(sp_frame,2,{delay:3,rotation:0*Math.PI});
            TweenMax.to(con_clock.scale,1,{delay:2,x:0.5,y:0.5,ease:Linear.easeNone});
            TweenMax.to(con_clock.scale,1,{delay:3,x:1,y:1,ease:Back.easeOut,onComplete:function () {
                int=self.setInterval(clock,15);
            }});
            con_clock.alpha=1;

            tip.alpha=0;
            TweenMax.to(tip,1,{delay:3,alpha:1});

            bg.alpha=0;
            TweenMax.to(bg,1.5,{delay:0,alpha:1});

            sp_frame.alpha=0;
            TweenMax.to(sp_frame,1,{delay:2,alpha:1,ease:Cubic.easeInOut});

            sp_clock.alpha=0;
            TweenMax.to(sp_clock,1,{delay:2.5,alpha:1,ease:Cubic.easeInOut});

            sp_m.alpha=0;
            TweenMax.to(sp_m,1,{delay:2.5,alpha:1,ease:Cubic.easeInOut});
            sp_h.alpha=0;
            TweenMax.to(sp_h,1,{delay:2.5,alpha:1,ease:Cubic.easeInOut});
            sp_center.alpha=0;
            TweenMax.to(sp_center,1,{delay:2.5,alpha:1,ease:Cubic.easeInOut});

            hand.x=-133;
            hand.y=575;
            hand.alpha=0
            TweenMax.to(hand,1.5,{delay:3.5,x:135,y:461,alpha:1,ease:Cubic.easeOut,onComplete:function()
            {
                hand.interactive=true;
            }});
        }
        function downHandler(e)
        {
            bool_down=true;
            startY=hand.y;
            downY= e.data.global.y;
        }
        function moveHandler(e)
        {
            if(bool_down)
            {

                if(tip.alpha>0.99)
                {
                    tip.alpha=0.98;
                    TweenMax.to(tip,1,{alpha:0});
                }
                if(e.data.global.y-downY<0)
                {
                    hand.y=startY+(e.data.global.y-downY);
                    if(hand.y<161)
                    {
                        hand.y=161;
                    }
                    else if(hand.y>461)
                    {
                        hand.y=461
                    }
                }
            }
            speed=(461-hand.y)/5000;
        }
        function upHandler(e)
        {
            bool_down=false;
        }

        // var int=self.setInterval(clock,15);
        function clock()
        {
            con_clock.scale.x+=speed;
            con_clock.scale.y+=speed;
            sp_frame.rotation+=(0.001+speed)*10;
            if(con_clock.scale.x>3.5)
            {

                TweenMax.to(con_clock,1,{alpha:0,ease:Linear.easeNone});
                hand.interactive=false;
                bool_down=false;

                clearInterval(int);

                var arr=[2,subIdx];
                var event = new CustomEvent("Game_PageIn",{'detail':arr});
                document.dispatchEvent(event);
            }

        }

        return page;
    }

}